//
//  OSUnfair_lockDemo.m
//  JKThreadTest
//
//  Created by 王冲 on 2018/10/24.
//  Copyright © 2018年 JK科技有限公司. All rights reserved.
//

#import "OSUnfair_lockDemo.h"
#import <os/lock.h>
@interface OSUnfair_lockDemo ()

@property(nonatomic,assign) os_unfair_lock ticketLock;
@property(nonatomic,assign) os_unfair_lock moneyLock;

@end

@implementation OSUnfair_lockDemo

-(instancetype)init{
    
    if (self = [super init]) {
        
        // 初始化锁
        // 买票的锁
        self.ticketLock = OS_UNFAIR_LOCK_INIT;
        self.moneyLock = OS_UNFAIR_LOCK_INIT;
    }
    
    return self;
}

-(void)__buyTicket{
    
    os_unfair_lock_lock(&_ticketLock);
    
    [super __buyTicket];
    
    os_unfair_lock_unlock(&_ticketLock);
    
}

-(void)__drawMoney{
    
    os_unfair_lock_lock(&_moneyLock);
    
    [super __drawMoney];
    
    os_unfair_lock_unlock(&_moneyLock);
}

-(void)__saveMoney{
    
    os_unfair_lock_lock(&_moneyLock);
    
    [super __saveMoney];
    
    os_unfair_lock_unlock(&_moneyLock);
}


@end
